<template>
  <div class="login-warapper">
    <div class="modal">
      <el-form ref="form" :model="form" :rules="rules">
        <div class="title">圆规</div>
        <el-form-item prop="userName">
          <el-input
            v-model="form.userName"
            prefix-icon="el-icon-user"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="userPwd">
          <el-input
            type="password"
            show-password
            v-model="form.userPwd"
            prefix-icon="el-icon-lock"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-button type="primary" class="btn-login" @click="onSubmit"
          >登录</el-button
        >
      </el-form>
    </div>
  </div>
</template>

<script>

export default {
  data () {
    return {
      form: {
        userName: '',
        userPwd: '',
      },
      rules: {
        userName: {
          required: true, message: '必填项不能为空', trigger: 'blur'
        },
        userPwd: {
          required: true, message: '必填项不能为空', trigger: 'blur'
        },
      }
    }
  },
  setup () {
  },
  methods: {
    onSubmit () {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return false
        }
        this.$api.login({ ...this.form }).then((res) => {
          // console.log(res)
          this.$store.commit('setUserInfo', res)
          this.$router.push('/')
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login-warapper {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f9fcff;
  width: 100vw;
  height: 100vh;
  .modal {
    width: 500px;
    padding: 50px;
    background-color: #fff;
    box-shadow: 0 0 10px 3px #ccc;
    .title {
      font-size: 50px;
      line-height: 50px;
      font-weight: bold;
      text-align: center;
      padding-bottom: 30px;
    }
    .btn-login {
      width: 100%;
    }
  }
}
</style>